package cn.aopmin.javase.simple;

import java.util.Random;
public class ConsoleRally {

  private static final Random random = new Random();

  public static void main(String[] args) {
    String s = "小马哥喝酒🍺";
    while (true) {
      randomPrint(s);
    }
  }

  /**
   *  随机抛硬币
   *  MEMO: 随机数 1-10 偶数正序输出 奇数倒序输出
   */
  private static void randomPrint(String s) {
    int num = random.nextInt(9) + 1;
    if (num % 2 == 0) {
      // 正序
      StringBuilder sb = new StringBuilder(s);
      s= sb.reverse().toString();
      printContent(s);
    } else {
      // 倒序
      printContent(s);
    }
    System.out.println();
  }

  /**
   * 控制台打印内容
   * @param s 字符串
   */
  private static void printContent(String s) {
    for (int i = 0; i < s.length(); i++) {
      System.out.print(s.charAt(i));
      try {
        Thread.sleep(50);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
}
// mac 格式化代码 option  command + L
